﻿using System.IO;
using System.Web.Hosting;
using Dexter.Storage;

namespace Dexter.Web.Mvc.ViewEngines {
	public class DexterVirtualFile : VirtualFile {
		readonly IStorageProvider storageProvider;

		public DexterVirtualFile ( string virtualPath , IStorageProvider storageProvider ) : base ( virtualPath ) {
			this.storageProvider = storageProvider;
		}

		public override Stream Open ( ) {
			var fullPath = storageProvider.GetPublicUrl ( VirtualPath );
			return storageProvider.GetFile ( fullPath ).OpenRead ( );
		}
	}
}